/*
 * @Author: Lin Hongwei
 * @Date: 2022-10-29 15:42:50
 * @LastEditTime: 2022-11-03 21:55:25
 * @LastEditors: Lin Hongwei
 * @email: 1365755396@qq.com
 * @CSDN: https://blog.csdn.net/weixin_45429409
 * @Description: 任务中间件
 */
/**
 * @description: 任务表单校验
 */
exports.taskValidatorMiddleware = (ctx, next) => {
  const { name, projectId, kanbanId } = ctx.request.body;
  if (!name || !projectId || !kanbanId) return ctx.fail("项目Id或任务名称或看板Id或经办人不能为空！");
  ctx.state.taskForm = { name, projectId, kanbanId };
  return next();
}
/**
 * @description: 任务排序移动表单校验
 * sortType - 1 移动后需要更新看板id
 */
exports.taskSortValidatorMiddleware = (ctx, next) => {
  const { fromId, toId, sortType = 1 } = ctx.request.body;
  if (!fromId || !toId) return ctx.fail("移动任务或目标任务的Id不能为空！");
  ctx.state.taskForm = [+fromId, +toId];
  ctx.state.sortType = sortType;//默认要进行看板id更新
  return next();
}

exports.taskSortValidatorMiddleware = (ctx,next)=>{
  const { fromId, toId = 0,kanbanId = 0 } = ctx.request.body;
  if (!fromId) return ctx.fail("移动Id不能为空！");
  if (!toId && !kanbanId) return ctx.fail("目标Id或者看板id不能为空！");
  ctx.state.sortForm = [+fromId, +toId,+kanbanId];
  return next();
}